<!--
 * @Descripttion: 
 * @Author: cbing
 * @Date: 2019-06-17 09:55:00
 * @LastEditors: cbing
 * @LastEditTime: 2019-09-05 10:05:36
 -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/Huploadify/Huploadify.css"/>
    <script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
</head>

<script>
    var url = "{:url('shop_store/lst')}";
    var checkAdname = "{:url('shop_store/checkAdname')}";
    var insertUrl = "{:url('shop_store/edit')}";
</script>

<body class="gray-bg">
<style>
    input.error{
        border:1px solid red;
    }
    span.error{
        padding-top:10px;
        color: #f00;
        font-size:12px;
    }
</style>

<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑门店</h5>
                </div>
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" id="form">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">门店名称：</label>
                            <div class="col-sm-6">
                                <input type="text" name="name" class="form-control" value="{$info['name']}">
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">门店联系人：</label>
                            <div class="col-sm-6">
                                <input type="text" name="contact" class="form-control" value="{$info['contact']}">
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">门店电话：</label>
                            <div class="col-sm-6">
                                <input type="text" name="phone" class="form-control" value="{$info['phone']}">
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="guanggao">
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">门店logo：</label>
                                <div class="col-sm-6">
                                    <div style="margin-bottom:7px; margin-top:5px;">
                                        <img id="imageinfo" {if condition="$info['logo']"}src="{$info['logo']}"{else/}src="__PUBLIC__/admin/img/nopic.jpg"{/if} width="100" height="100" border="0" />
                                        <br/><button type="button" class="btn btn-danger btn-xs del" style="display:none;">删除</button>
                                    </div>
                                    <div id="uploaderInput"></div>
                                    <input type="hidden" name="logo" value="{$info['logo']}" >
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">店铺省.市.区/县:</label>
                            <div class="col-sm-2">
                                <select class="form-control m-b" name="pro_id">
                                    {foreach name="prores" item="v"}
                                    <option {if condition="$info['pro_id'] eq $v['id']"}selected="selected"{/if} value="{$v.id}"}>{$v.zm}.{$v.pro_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <div class="col-sm-2">
                                <select class="form-control m-b" name="city_id" id="cityname">
                                    {foreach name="cityres" item="v"}
                                    <option {if condition="$info['city_id'] eq $v['id']"}selected="selected"{/if} value="{$v.id}">{$v.zm}.{$v.city_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <div class="col-sm-2">
                                <select class="form-control m-b" name="area_id" id="areaname">
                                    {foreach name="areares" item="v"}
                                    <option {if condition="$info['area_id'] eq $v['id']"}selected="selected"{/if} value="{$v.id}">{$v.zm}.{$v.area_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">详细地址：</label>
                            <div class="col-sm-6">
                                <textarea name="address_detail" class="form-control">{$info['address_detail']}</textarea>
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">营业开始时间：</label>
                            <div class="col-sm-6">
                                <input type="text" name="work_end_time" class="form-control" value="{$info['work_start_time']}">
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">营业结束时间：</label>
                            <div class="col-sm-6">
                                <input type="text" name="work_start_time" class="form-control" value="{$info['work_end_time']}">
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">店铺所在位置：</label>
                            <div class="col-sm-6">
                                <input type="text" name="latlon" value='{if condition="$info['latitude'] and $info['longitude']"}{$info['latitude']},{$info['longitude']}{/if}' class="form-control" readonly="readonly"/>
                            </div>
                            <div class="col-sm-1"><button class="btn btn-info" type="button" id="zbxz">打开坐标选择器</button></div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;margin-left:55px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">门店简介：</label>
                            <div class="col-sm-6">
                                <textarea name="detail" class="form-control">{$info['detail']}</textarea>
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">自提：</label>
                            <div class="col-sm-6">
                                <label class="radio-inline"><input type="radio" name="self_pick_up" value="1" {if condition="$info['self_pick_up'] eq 1"}checked="checked"{/if}>是</label>
                                <label class="radio-inline"><input type="radio" name="self_pick_up" value="0" {if condition="$info['self_pick_up'] eq 0"}checked="checked"{/if}>否</label>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">核销：</label>
                            <div class="col-sm-6">
                                <label class="radio-inline"><input type="radio" name="collate" value="1" {if condition="$info['collate'] eq 1"}checked="checked"{/if}>是</label>
                                <label class="radio-inline"><input type="radio" name="collate" value="0" {if condition="$info['collate'] eq 0"}checked="checked"{/if}>否</label>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">是否开启：</label>
                            <div class="col-sm-6">
                                <label class="radio-inline"><input type="radio" name="status" value="1" {if condition="$info['status'] eq 1"}checked="checked"{/if}>是</label>
                                <label class="radio-inline"><input type="radio" name="status" value="0" {if condition="$info['status'] eq 0"}checked="checked"{/if}>否</label>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <input type="hidden" name="id" value="{$info['id']}" />

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="submit" id="doSubmit" style="margin-right:20px;">保存内容</button>
                                <button type="reset" class="btn btn-default">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 全局js -->
<script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
<!-- 自定义js -->
<script type="text/javascript" src="__PUBLIC__/admin/Huploadify/jquery.Huploadify.js"></script>
<script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
<script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>
<!-- iCheck -->
<script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
<script src="__PUBLIC__/admin/js/common/ajax.js"></script>

<script>
    $(function(){
        $('select[name=pro_id]').change(function(){
            var pro_id = $(this).val();
            if(pro_id != '' && pro_id != 0){
                $.ajax({
                    url:"{:url('shops/getcitylist')}",
                    type:'POST',
                    data:{'pro_id':pro_id},
                    dataType:'json',
                    success:function(data){
                        if(data){
                            var html = '';
                            var html='<option value="">--选择市--</option>';
                            $.each(data,function(i,v){
                                html+='<option value="'+v.id+'">'+v.zm+'.'+v.city_name+'</option>';
                            });
                            $('#cityname').html(html);
                            var html2='<option value="">--选择区/县--</option>';
                            $('#areaname').html(html2);
                        }else{
                            var html='<option value="">--选择市--</option>';
                            var html2='<option value="">--选择区/县--</option>';
                            $('#cityname').html(html);
                            $('#areaname').html(html2);
                        }
                    }
                });
            }else{
                var html='<option value="">--选择市--</option>';
                var html2='<option value="">--选择区/县--</option>';
                $('#cityname').html(html);
                $('#areaname').html(html2);
            }
        });

        $('select[name=city_id]').change(function(){
            var city_id = $(this).val();
            if(city_id != '' && city_id != 0){
                $.ajax({
                    url:"{:url('shops/getarealist')}",
                    type:'POST',
                    data:{'city_id':city_id},
                    dataType:'json',
                    success:function(data){
                        if(data){
                            var html = '';
                            var html='<option value="">--选择区/县--</option>';
                            $.each(data,function(i,v){
                                html+='<option value="'+v.id+'">'+v.zm+'.'+v.area_name+'</option>';
                            });
                            $('#areaname').html(html);
                        }else{
                            var html='<option value="">--选择区/县--</option>';
                            $('#areaname').html(html);
                        }
                    }
                });
            }else{
                var html='<option value="">--选择区/县--</option>';
                $('#areaname').html(html);
            }
        });

        $('#zbxz').click(function(){
            var zbUrl = "{:url('shop_store/teng_xun_map')}";
            layer.open({
                type : 2,
                title : '选择坐标',
                shadeClose : true,
                shade : 0.5,
                area : ['600px','600px'],
                content : zbUrl
            });
        });



        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });

        $('.guanggao').hide();
        $('.guanggao').eq(0).show();
        $('.adurl').hide();
        $('.adurl').eq(0).show();
        $('#atype .radio-inline').click(function(){
            var i = $(this).index();
            $('.guanggao').hide();
            $('.guanggao').eq(i).show();
            $('.adurl').hide();
            $('.adurl').eq(i).show();
        });

        //上传缩略图
        $('#uploaderInput').Huploadify({
            uploader : '{:url("Common/Upload/uploadPic")}',
            method:'post',
            formData: {name:'ad'},//发送给服务端的参数，格式：{key1:value1,key2:value2}
            buttonText : '上传图像',
            removeTimeout: 2000,
            fileTypeDesc:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;',
            fileTypeExts:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;',
            fileObjName: 'file', //上传附件$_FILE标识
            fileSizeLimit : 2048,
            //showUploadedPercent:false,//是否实时显示上传的百分比，如20%
            auto : true, //开启,自动上传
            multi : false, //开启,多选文件
            //开始上传
            onUploadStart:function(file){
                layer.load(2);
            },
            onUploadSuccess : function(file, data, response) {
                //解析成json对象
                eval('var data='+data);
                if(data.status == 200){
                    var picpath = data.data.path;
                    $('#imageinfo').attr('src', picpath);
                    $('.del').show();
                    $('input[name=logo]').val(picpath);
                }else{
                    layer.msg(data.mess, {icon: 2,time: 2000});
                }
            },
            //上传完成后执行的操作
            onUploadComplete:function(file){
                layer.closeAll('loading');
            },
            //上传错误
            onUploadError : function(file, errorCode, errorMsg, errorString) {
                layer.msg('文件' + file.name + '上传失败:' + errorString, {icon: 2,time: 2000});
            }
        });

        //上传缩略图
        $('#uploaderBgImage').Huploadify({
            uploader : '{:url("Common/Upload/uploadPic")}',
            method:'post',
            formData:null,//发送给服务端的参数，格式：{key1:value1,key2:value2}
            buttonText : '上传背景图',
            removeTimeout: 2000,
            fileTypeDesc:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;',
            fileTypeExts:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;',
            fileObjName: 'filedata', //上传附件$_FILE标识
            fileSizeLimit : 2048,
            //showUploadedPercent:false,//是否实时显示上传的百分比，如20%
            auto : true, //开启,自动上传
            multi : false, //开启,多选文件
            //开始上传
            onUploadStart:function(file){
                layer.load(2);
            },
            onUploadSuccess : function(file, data, response) {
                //解析成json对象
                eval('var data='+data);
                if(data.status == 200){
                    var picpath = data.data.path;
                    $('#bgimage').attr('src',picpath);
                    $('input[name=logo]').val(picpath);
                }else{
                    layer.msg(data.mess, {icon: 2,time: 2000});
                }
            },
            //上传完成后执行的操作
            onUploadComplete:function(file){
                layer.closeAll('loading');
            },
            //上传错误
            onUploadError : function(file, errorCode, errorMsg, errorString) {
                layer.msg('文件' + file.name + '上传失败:' + errorString, {icon: 2,time: 2000});
            }
        });

        $('.del').click(function(){
            $('input[name=logo]').val('');
            $('#imageinfo').attr('src','__PUBLIC__/admin/img/nopic.jpg');
            $('.del').hide();
        });

        var icon = "<i class='fa fa-times-circle'></i>&nbsp;&nbsp;";
        $('#form').validate({
            errorElement : 'span',
            debug: true,//只验证不提交表单
            //layer ajax提交表单
            submitHandler:function(){
                // 序列化 表单数据 后提交 ，太简洁了
                post(insertUrl,'POST',$('#form').serialize(),1);
                return false;
            },//这是关键的语句，配置这个参数后表单不会自动提交，验证通过之后会去调用的方法

            rules:{
                name:{
                    required:true,
                    remote : {
                        url : checkAdname,
                        type : 'post',
                        dataType : 'json',
                        data : {
                            name : function () {
                                return $('input[name=name]').val();
                            },
                            id : function () {
                                return $('input[name=id]').val();
                            }
                        }
                    }
                },
                contact:{required:true},
                phone:{required:true},
                logo:{required:true},
                pro_id:{required:true},
                city_id:{required:true},
                area_id:{required:true},
                detail:{required:true},
                work_start_time:{required:true},
                work_end_time:{required:true},
                latlon:{required:true},
                address_detail:{required:true},
            },

            messages:{
                name:{
                    required:icon+'必填',
                    remote:icon+'名称已存在'
                },
                contact:{required:icon+'必选'},
                phone:{required:icon+'必选'},
                logo:{required:icon+'必选'},
                pro_id:{required:icon+'必选'},
                city_id:{required:icon+'必选'},
                area_id:{required:icon+'必选'},
                detail:{required:icon+'必选'},
                work_start_time:{required:icon+'必选'},
                work_end_time:{required:icon+'必选'},
                latlon:{required:icon+'必选'},
                address_detail:{required:icon+'必选'},
            }
        });
    });

    function cl(){
        location.href = url;
    }
</script>

</body>
</html>